import {ref, watch, reactive, getCurrentInstance} from 'vue'
import {Search, Plus, Upload} from '@element-plus/icons-vue'
import {ElMessage} from 'element-plus'
import request from '@/utils/request'
import courseComp from './component/courseComp'
import buttonAction from './component/buttonAction'
import allPracticeComp from './component/allPracticeComp'
import lastTestComp from './component/lastTestComp'
import  $button from '@/button'
const proxy = getCurrentInstance();

export const tableItem = reactive({
    select: false,
    index: !true,
    tree: true,
    expandAll: true,
    align: 'center',
    column: [
        {
            label: '姓名',
            prop: 'studentName',
            align: 'center',
            width: '100'
        },
        {
            label: '科目名称',
            prop: 'courseName',
            align: 'center',
            component: courseComp,
            width: '250'
        },
        {
            label: '所属机构',
            prop: 'insName',
            align: 'center',
            width: '200',
            closeShow: null
        },
        {
            label: '批次号',
            prop: 'batchNum',
            align: 'center',
            width: '150'
        },
        {
            label: '登录次数',
            prop: 'loginNum',
            align: 'center',
            width: '100'
        },
        {
            label: '最近登录时间',
            prop: 'lastLoginTime',
            align: 'center',
            width: '150'
        },
        {
            label: '最近练习日期',
            prop: 'lastPracticeDate',
            align: 'center',
            width: '120'
        },
        {
            label: '总练习情况',
            align: 'center',
            prop: 'practiceInfo',
            // component: allPracticeComp,
            // width: '200'
        },
        {
            label: '最近测试情况',
            align: 'center',
            prop: 'lastTestInfo',
            // component: lastTestComp,
            // width: '200'
        },
        {
            label: '操作',
            prop: 'action',
            align: 'center',
            component: buttonAction,
            width: '250'
        }
    ],
    pageInfo: {
        request: {
            'studentName': '',
            'courseId': '',
            'pageDomain': {
                'pageNum': '1',//分页页面数
                'pageSize': '10',//分页页面数据大小
                'orderByColumn': '',//搜索参数
                'isAsc': '',//搜索参数
                'reasonable': ''//搜索参数
            }
        },
        pagesClose: false,//是否开启分页
        url: '/train/count/page',//分页路由，不传的话需要传入自定义的分页函数paging 传入时定义的分页函数paging会失效
        method: 'POST',//分页请求方法，不传默认为POST
        // 分页函数paging
        paging: function () {
        }
    },
    // 分页数据 自定义分页函数paging时需要把值赋给tableData
    tableData: {
        total: '',//分页总计
        // 分页数据
        rows: []
    },
    // 操作栏按钮
    btnArray: [
        {
            label: '登录日志',
            type: 'primary',
            plain: true,//镂空按钮  优先文字按钮
            text: true,//文字按钮
            hasPermi: [$button.traincountpagelogin|| null],
            customParameters: 'view',//自定义函数参数
            show: true,//是否显示
            // 按钮方法
            handle: function (row) {
            }
        },
        {
            label: '练习情况',
            type: 'primary',
            plain: true,//镂空按钮  优先文字按钮
            text: true,//文字按钮
            hasPermi: [$button.studenthistorytrainPage|| null],
            customParameters: 'edit',//自定义函数参数
            show: true,//是否显示
            // 按钮方法
            handle: function (row) {
            }
        },
        {
            label: '测试情况',
            type: 'primary',
            text: true,
            hasPermi: [$button.studenthistorytestPage|| null],
            show: true,//是否显示
            handle: function (row) {
            }
        },
    ],
    moreBtnArrayText: '',
    moreBtnArray: [],
        // 选择框触发
    selectChange: function (row) {
    },
}
)

export const operationItem = reactive({
    defaultSearch: false,
    defaultRefresh: false,
    SearchItem: [
        {
            code: 'studentName',
            name: '姓名',
            type: 'input',
            placeholder: '姓名'
        },
        {
            code: 'subjectArray',
            name: '科目',
            type: 'cascader',
            placeholder: '请选择科目',
            options: []
        },
        {
            code: 'insId',
            name: '所属机构',
            type: 'select',
            value: 'userId',
            label: 'nickName',
            options: [
                { label: '全部', value: 1 },
            ]
        },
        {
            code: "batchNum",
            name: '批次号',
            type: 'input',
            placeholder: '批次号'
        },
        {
            code: "daterange",//
            startName: "导入开始日期", //默认是开始时间 type为 daterange生效
            rangeName: "", //默认是至 type为 daterange生效
            endName: "导入结束日期", //默认是结束时间 type为 daterange生效
            valueFormat: "", //默认是YYYY-MM-DD
            placeholder: "请选择日期",//默认是请选择日期type为date生效
            type: "daterange",//daterange或date
        }
    ],
    menuArray: [
        {
            show: true,
            type: 'primary',
            text: '查询',
            icon: Search,
            handle: () => {
            }
        },
        {
            show: true,
            type: 'primary',
            text: '导出',
            // studenthistorytestPage traincountexport
            hasPermi: [$button.traincountexport|| ''],
            icon: Upload,
            handle: () => {
            }
        },
    ]
})

// 统计分页
export function practicePagingApi(dataRequest) {
    return request({
        url: '/train/count/page',
        method: 'POST',
        data:dataRequest
    })
}
//登录日志
export function loginLogApi(dataRequest) {
    return request({
        url: '/train/count/page/login',
        method: 'POST',
        data:dataRequest
    })
}
//练习统计导出
export function trainExportApi(dataRequest) {
    return request({
        url: '/train/count/export',
        method: 'POST',
        data:dataRequest
    })
}
//练习详情
export function trainDetailApi(dataRequest) {
    return request({
        url: '/student/train/history/page',
        method: 'POST',
        data:dataRequest
    })
}


